const path = require('path');
const webpack = require('webpack');
const Dashboard = require('webpack-dashboard');
const DashboardPlugin = require('webpack-dashboard/plugin'); //格式化输出命令行webpack的日志
const Parame = require('./public/constants');
const baseConfig = require('./baseConfig');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const HtmlWebpackHarddiskPlugin = require('html-webpack-harddisk-plugin'); //即使在开发模式也将html文件写入到硬盘中

let config = Object.assign({}, baseConfig, {
  entry: {
    [Parame.mainJsName]: [
      'webpack-dev-server/client?http://127.0.0.1:' + Parame.devPort,
      'webpack/hot/only-dev-server',
      path.join(Parame.srcPath, 'entry')
    ]
  },
  cache: true,
  devtool: 'cheap-module-eval-source-map',
  plugins: [
    new webpack.HotModuleReplacementPlugin(),
    new webpack.NamedModulesPlugin(), //热替换(HRM)时显示哪个模块改动
    new webpack.LoaderOptionsPlugin({
      minimize: false, //不压缩loader
      debug: true
    }),
    new webpack.NoEmitOnErrorsPlugin(),
    new HtmlWebpackPlugin(Parame.HtmlPluginConfig),
    new HtmlWebpackHarddiskPlugin(),
    new DashboardPlugin(new Dashboard().setData),
  ],

});

config.module.rules.push({
  test: /\.jsx?$/,
  use: [{loader: 'react-hot-loader'}, {loader: 'babel-loader'}],
  include: Parame.srcPath
}, {
  test: /\app.scss$/i,
  use: [{
    loader: 'bundle-loader',
    options: {name: 'AppCss'}
  }, {loader: 'style-loader'}, {
    loader: 'css-loader',
    options: {sourceMap: true}
  }, {loader: 'postcss-loader'}, {
    loader: 'sass-loader',
    options: {sourceMap: true}
  }]
});


module.exports = config;
